/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Project: javaseapp - ListStudentSort
 * <p>Powered by webrx On 2021-08-20 14:44:44
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class ListStudentSort {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        list.add(new Student(1, "李四", 30));
        list.add(new Student(2, "赵六", 90));
        list.add(new Student(3, "张三丰", 80));
        list.add(new Student(4, "李强", 70));
        System.out.println(list);
        //list.sort((s1, s2) -> s1.getName().compareTo(s2.getName()));
        //list.sort((s1, s2) -> s2.getName().compareTo(s1.getName()));
        //根据学生对象的姓名排序 升序
        //list.sort(Comparator.comparing(Student::getName));
        //根据学生成绩排序 升序
        //list.sort(Comparator.comparingInt(Student::getScore));
        //根据id降序
        list.sort((a, b) -> b.getId() - a.getId());
        System.out.println(list);

    }
}
